You inspect a container using the docker inspect command, which returns detailed JSON metadata about the container's configuration, state, networking, volumes, and more.
The docker inspect command is the primary tool for retrieving low-level information about Docker containers and images. It outputs a JSON array containing comprehensive metadata such as the container's IP address, port mappings, environment variables, mount points, network settings, and current state. This is essential for debugging, understanding container configurations, and scripting automation tasks.
The raw JSON output can be overwhelming, but tools like jq help parse it. Common fields to examine include .State (running status, exit code, start time), .NetworkSettings.Networks (IP addresses, network configuration), .Mounts (volume and bind mount details), .Config.Env (environment variables), and .Config.Cmd (the command the container runs). For quick inspection of specific values, use the --format flag with Go template syntax.
The inspect command works on both running and stopped containers. For stopped containers, you'll still see configuration details like environment variables and mount points, though network information may be incomplete since the container's network namespace is no longer active. This is useful for troubleshooting why a container failed to start.
docker inspect -f '{{.State.Status}}' container - Get container status (running, exited, etc.)
docker inspect -f '{{.State.ExitCode}}' container - Get exit code (for debugging failures)
docker inspect -f '{{.Config.Image}}' container - Get the image the container was created from
docker inspect -f '{{range .Mounts}}{{.Source}} -> {{.Destination}}\n{{end}}' container - List all mount points
docker inspect -f '{{json .Config.Labels}}' container | jq - View container labels
docker inspect -f '{{.HostConfig.RestartPolicy.Name}}' container - Check restart policy
For containers running in a network, inspect reveals important network details: the container's IP address (useful for troubleshooting connectivity between containers), the network driver in use, and the MAC address. When containers use custom networks, inspect shows which networks they belong to and their IP assignments within each network.